package controller.admin;

import com.mysql.cj.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import pojo.User;
import service.user.UserService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/admin")
public class MemberAddController {

    @Autowired
    private UserService userService;
    public void setUserService(UserService userService) {
        this.userService = userService;
    }
    @RequestMapping("/addmember")
    public String AddMember(Model model, HttpSession session, HttpServletResponse response, HttpServletRequest request){
        String username = request.getParameter("username");
        String cid = request.getParameter("cid");

        String number = request.getParameter("number");
        String phone = request.getParameter("phone");
        String email = request.getParameter("email");
        String sex = request.getParameter("sex");
        int gender = Integer.parseInt(sex);
        String pass = request.getParameter("pass");
        User user = new User(number,username,gender,phone,pass,cid,email);
        int i = userService.addUser(user);

        model.addAttribute("msg","添加失败");
        if (i>0){
            model.addAttribute("msg","添加成功！");

            System.out.println("success add");
        }
        else {
            System.out.println("failed add");
        }
        return "member-add";

    }
}
